package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.service.UserPermissionConnectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 邓龙飞
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/user-permission-connect")
@Api(tags = "权限管理表")
public class UserPermissionConnectController {

    @Autowired
    UserPermissionConnectService userPermissionConnectService;

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 用户添加admin权限
    */
    @ApiOperation("赋予admin权限，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("addAdmin")
    public RespBean addAdmin(Integer id){
        return userPermissionConnectService.addAdmin(id);
    }

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 回收admin权限
    */
    @ApiOperation("回收admin权限，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("loseAdmin")
    public RespBean loseAdmin(Integer id){
        return userPermissionConnectService.loseAdmin(id);
    }

    /**
     * @Author: 邓龙飞
     * @Date:
     * @Description: 用户添加boss权限
     */
    @ApiOperation("赋予boss权限，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("addBoss")
    public RespBean addBoss(Integer id){
        return userPermissionConnectService.addBoss(id);
    }

    /**
     * @Author: 邓龙飞
     * @Date:
     * @Description: 回收boss权限
     */
    @ApiOperation("回收boss权限，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("loseBoss")
    public RespBean loseBoss(Integer id){
        return userPermissionConnectService.loseBoss(id);
    }


}

